const Koa = require("koa");
const server = new Koa();
const router = require("koa-router")();
const parser = require("koa-parser");
const cors = require("koa2-cors");
server.use(cors())
server.use(parser());

let studentList = [
    {
        id:"王佳伟",
        password:"123456",
        e_mail:"1951253781@qq.com",
        sex:["男"],
        hobby:["篮球"]
    },
    {
        id:"王佳伟",
        password:"123456",
        e_mail:"1951253781@qq.com",
        sex:["男"],
        hobby:["篮球"]
    },
    {
        id:"王佳伟",
        password:"123456",
        e_mail:"1951253781@qq.com",
        sex:["男"],
        hobby:["篮球"]
    }
]
router.get("/student" , async ctx => {
    ctx.body = studentList
})  
router.post("/student" , async ctx => {
    let student = ctx.request.body.student;
    studentList.push(student);
    ctx.body = studentList
    ctx.body = true
})
router.delete("/student/:id" , async ctx => {
    let id = ctx.params.id;
    console.log(id)
    studentList.splice(id,1);
    ctx.body = true
})
router.delete("/student/:j",async ctx=>{
    let ind = ctx.params.j;
    let setfruit = ctx.request.body.modfruit;
    arr.splice(ind,1,setfruit);
    ctx.body = true;
})
router.put("/student/:index", async ctx => {
    let index = ctx.params.index;
    let setFruit = ctx.request.body.setFruit;
    fruitList.splice(index,1,setFruit);
    ctx.body = true;
})
server.use(router.routes());
server.listen(3000 , () => {
    console.log("3000端口")
})